package com.thenie.controller;

import com.thenie.pojo.Floor;
import com.thenie.pojo.Room;
import com.thenie.pojo.RoomType;
import com.thenie.service.FloorService;
import com.thenie.service.RoomService;
import com.thenie.service.RoomTypeService;
import com.thenie.vo.FloorVo;
import com.thenie.vo.RoomTypeVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Controller
public class IndexController {
    @Resource
    private RoomTypeService roomTypeService;
    @Resource
    private FloorService floorService;
    @Resource
    private RoomService roomService;
    @RequestMapping("/index.html")
    public String index(Model model){
        HashMap<String, Object> map = new HashMap<String, Object>();
        //查询房型列表
        List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(new RoomTypeVo());
        //查询楼层列表
        List<Floor> floorList = floorService.findFloorList(new FloorVo());

        for (Floor floor:floorList){//根据楼层的Id查询房间的信息（包括价格）
            Integer floorId = floor.getId();//楼层Id
            String floorName = floor.getName();//楼层的名称
            //根据楼层查询房间
            List<Room> roomByFloorId = roomService.findRoomByFloorId(floorId);
            map.put(floorName,roomByFloorId);
        }
        model.addAttribute("roomTypeList", roomTypeList);
        model.addAttribute("floorList",floorList);
        model.addAttribute("roomMap", map);
        return "forward:/home.jsp";
    }
}
